package com.digital.smartgrow.controller.upscale;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.upscale.UpScalePageDTO;
import com.digital.smartgrow.dto.upscale.UpscaleDTO;
import com.digital.smartgrow.entity.upscale.UpScale;
import com.digital.smartgrow.service.upscale.UpScaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 晋升指标 前端控制器
 * </p>
 *
 * @author sunyuechao
 * @since 2022-07-12
 */
@Api(tags = "晋升指标")
@RestController
@RequestMapping("${context.prefix}/syc/upScale")
public class UpScaleController {

    @Autowired
    private UpScaleService upScaleService;

    @ApiOperation(value = "晋升指标-分页查询")
    @PostMapping("/list")
    public Object getListByPage(@RequestBody UpScalePageDTO upScalePageDTO){
        return upScaleService.getListByPage(upScalePageDTO);
    }

    @ApiOperation(value = "晋升指标-详情")
    @GetMapping("/{id}")
    public Object getInfo(@PathVariable Integer id){
        if (id == null) return Result.fail("id不能为空");
        return upScaleService.getInfo(id);
    }

    @ApiOperation(value = "晋升指标-删除")
    @DeleteMapping("/{id}")
    public Object removeById(@PathVariable Integer id){
      if (id == null) return Result.fail("id不能为空");
      return upScaleService.removeById(id);
    }
    @ApiOperation(value = "晋升指标-新增")
    @PostMapping()
    public Object add( @RequestBody UpScale upScale){
       return upScaleService.save(upScale);
    }

    @ApiOperation(value = "晋升指标-编辑")
    @PutMapping()
    public Object edit(@RequestBody UpScale upScale){
    if (upScale==null||upScale.getId() == null)
       return Result.fail("id不能为空");
       return upScaleService.updateById(upScale);
    }

    @ApiOperation(value = "晋升指标-保存")
    @PutMapping("/save")
    public Object save(@RequestBody UpscaleDTO upScale){
//        if (upScale==null||upScale.getId() == null)
//            return Result.fail("id不能为空");
        return upScaleService.saveBat(upScale);
    }
}
